{include file="common/top" /}
<div>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class=" ">
                <table class="layui-hide" id="test" lay-filter="test"></table>
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="getAdd">添加小组</button>
                    </div>
                </script>
                <script type="text/html" id="barDemo">
                    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
                </script>
                
               
            </div>
        </div>
    </div>
</div>
{include file="common/footer" /}
<script>
    //添加
    function get_add() {
        layer.open({
            type: 2,
            title: '添加小组',
            area: ['50%', '60%'],
            fixed: false, //不固定
            maxmin: true,
            shadeClose: true,
            scrollbar: false, //- 是否允许浏览器出现滚动
            content: "{:url('group_add')}" 
        });
        //layer.full(index);
    }

    //编辑
    function get_save(id) {
        layer.open({
            type: 2,
            title: '编辑小组',
            area: ['50%', '60%'],
            fixed: false, //不固定
            maxmin: true,
            shadeClose: true,
            scrollbar: false, //- 是否允许浏览器出现滚动
            content: "{:url('group_save')}?id=" + id
        });
        //layer.full(index);
    }
    // 删除
    function  get_del(id,obj){
        layer.load(1, { shade : [ 0.5, '#676a6c' ] });
			$.post("{:url('get_yy_del')}?t=json",{id:id},function(data){
				layer.closeAll();
				if (data['code'] == 1) {
                    obj.del(); 
					layer.msg(data['msg'], { icon : 6 });
				} else {
					layer.msg(data['msg'], { icon : 5 });
				}
			});
    }

	
    var form, table;
    layui.use('table', function () {
    	pageLoading();
        table = layui.table, form = layui.form;
        table.render({
            elem: '#test',
            height: 'full-60',
            url: '{:url("group")}?t=json',
            method: 'post',
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            id: 'testReload',
            page: {limit: 30},
            skin: 'line',
            loading:false,
            cols: [[
                {field: 'name', title: '小组名称',width:120},
                {field: 'username', title: '组长',width:120},
                {field: 'member', title: '成员',width:'77%'},
                {fixed: 'right', width: '8%', title: '操作', toolbar: '#barDemo'}
            ]],
            done: function () {
                // 添加分页加载动画的函数    
                $('.layui-laypage > a').each(function(){
                    $(this).attr('onclick',"pageLoading(this)");
                })
                layer.close(loadingIndex);
            }
        });
        
        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            switch (obj.event) {
                case 'getAdd':
                    get_add();
                break;
            }

        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(data.id)
            switch (obj.event) {
                case 'edit':
                    get_save(data.id);
                    break;
                case 'del':
                    get_del(data.id,obj);
                    break;
            }

        });

    });

    
    //重载数据表
    function get_s(msg) {
        table.reload('testReload', {
            url: '{:url("group")}?t=json',
        });
        layer.msg(msg, {icon: 6});
    }

</script>